package financier.jfz.com.babycare.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import financier.jfz.com.babycare.R;

public class BaseActivity extends AppCompatActivity {
    ViewGroup root_group;
    ToolbarControl toolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.base_layout);
        toolbar = findViewById(R.id.about_me_toolbar);
        initToolBar();
    }

    protected ToolbarControl getToolbar() {
        return toolbar;
    }

    @Override
    public void setContentView(int layoutResID) {
        if (root_group == null) {
            root_group = findViewById(R.id.root_group);
        }
        root_group.addView(LayoutInflater.from(this).inflate(layoutResID, root_group, false));
    }
    protected void backPress(){
        finish();
    }

    @Override
    public void onBackPressed() {
        backPress();
    }

    private void initToolBar() {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbar.setLeftTitleClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                backPress();
            }
        });
    }
}
